package com.gamotech.schoollifedemo.utils

import android.content.Context
import android.content.SharedPreferences

class SharedPreferenceUtils private constructor(context: Context) {
    private var context: Context? = context
    private var sharedPreferences: SharedPreferences? = null

    companion object {
        fun createSharedPreferenceUtils(context: Context): SharedPreferenceUtils {
            return SharedPreferenceUtils(context)
        }
    }

    init {
        this.sharedPreferences =
            this.context?.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)
    }


    fun putValue(key: String, value: Boolean) {
        val editor = sharedPreferences?.edit()
        editor?.putBoolean(key, value)
        editor?.apply()
    }

    fun putValue(key: String, value: Long) {
        val editor = sharedPreferences?.edit()
        editor?.putLong(key, value)
        editor?.apply()
    }

    fun putValue(key: String, value: String) {
        val editor = sharedPreferences?.edit()
        editor?.putString(key, value)
        editor?.apply()
    }

    fun putValue(key: String, value: Int) {
        val editor = sharedPreferences?.edit()
        editor?.putInt(key, value)
        editor?.apply()
    }

    fun putValue(key: String, value: Float) {
        val editor = sharedPreferences?.edit()
        editor?.putFloat(key, value)
        editor?.apply()
    }

    fun getValue(key: String, defaultValue: Int): Int? {
        return sharedPreferences?.getInt(key, defaultValue)
    }

    fun getValue(key: String, defaultValue: Float): Float? {
        return sharedPreferences?.getFloat(key, defaultValue)
    }

    fun getValue(key: String, defaultValue: String): String? {
        return sharedPreferences?.getString(key, defaultValue)
    }

    fun getValue(key: String, defaultValue: Boolean): Boolean? {
        return sharedPreferences?.getBoolean(key, defaultValue)
    }

    fun getValue(key: String, defaultValue: Long): Long? {
        return sharedPreferences?.getLong(key, defaultValue)
    }

}